import React, { useState } from 'react';
import './albumChild.less';
import { Button, Mask, Space } from 'antd-mobile';
import { history, useLocation } from 'umi';
import axios from 'axios';

export default function albumChild() {
  let location = useLocation();
  // 个人信息
  const [personalInfo, setPersonalInfo] = useState(
    JSON.parse(sessionStorage.getItem('userdata') || '{}') || '',
  );

  // 修改头像
  const xiutou = async () => {
    let {
      data: { code, msg },
    } = await axios.post('/api/mine/updtou', {
      id: personalInfo._id,
      tou: location.search.slice(6),
    });
    if (code === 200) {
      history.push('/hello/mine');
    }
  };

  return (
    <div className="albumchild">
      <div className="albumchild-top">
        <p>选取照片</p>
      </div>
      <div className="albumchild-img">
        <div
          className="img"
          style={{
            backgroundImage: `url(${location.search.slice(6)} )`,
            backgroundSize: '100%',
          }}
        >
          <div className="mask">
            <div className="luminance">
              <img src={location.search.slice(6)} alt="" />
            </div>
          </div>
        </div>
      </div>
      <div className="albumchild-buttom">
        <div onClick={() => history.push('/album')}>取消</div>
        <div onClick={xiutou}>确定</div>
      </div>
    </div>
  );
}
